<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    <link rel='stylesheet' href='<%- rootUrl %>/res/adapter.css' />
    <style>
        .adapt-panel > div {margin:6px}
    </style>
    <title>修改密码</title>
    <script src="<%- rootUrl %>/node_modules/jquery/dist/jquery.min.js"></script>
    <script src="<%- rootUrl %>/res/adapter.js"></script>
</head>
<body class="body-margin">
<alljs-widget><message-top><%- message %></message-top></alljs-widget>
<h2>修改密码</h2>
<form class="common-style" method="post" action="./signpassword" style="width:100%;" onsubmit="return submitCheck()" onkeypress="return event.keyCode !== 13;">
    <input type="hidden" name="tid" value="" />
    <div class="adapt-panel">
        <div>
            <span>新密码&emsp;</span>
            <input type="password" name="password_new" />
        </div>
        <div>
            <span>再次输入</span>
            <input type="password" name="password_confirm" />
        </div>
        <div id="ori-pwd-div" style="display:none">
            <span>原密码&emsp;</span>
            <input type="password" name="password" />
        </div>
        <div>
            <span>验证码&emsp;</span>
            <input type="text" name="captcha" style="width:57px" />
            <img id="captcha-img" style="vertical-align: top; margin:6px" height="32" onclick="this.setAttribute('src','./captcha?'+new Date().getTime())" />
        </div>
        <div>
            <input type="submit" value="确认" style="vertical-align: middle" />
            <input type="button" value="取消" style="vertical-align: middle" onclick="history.length > 0 ? history.go(-1) : close()" />
        </div>
    </div>
</form>
<script>
document.getElementById('captcha-img').onclick();

var tid = window.getUrlParam('tid');
if (tid == null || tid === ''){
    document.getElementById('ori-pwd-div').style.display = '';
}else{
    document.getElementsByName('tid')[0].value = tid;
}

var submitCheck = function(){
    let val = null;
    val = document.getElementsByName('captcha')[0].value;
    if (val.length === ''){
        showMessage('请输入验证码');
        return false;
    }
    val = document.getElementsByName('password_new')[0].value;
    if (val.length < 6){
        showMessage('密码最少6位');
        return false;
    }
    val = document.getElementsByName('password_new')[0].value;
    if (val.length < 6){
        showMessage('新密码最少6位');
        return false;
    }
    if (val !== document.getElementsByName('password_confirm')[0].value){
        showMessage('两次输入密码不相同');
        return false;
    }
    return true;
}
</script>
</body>
</html>